import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:webview_flutter/webview_flutter.dart';

import '../widgets/base_page.dart';

class H5Page extends BasePage {
  const H5Page({super.key});

  @override
  BasePageState<H5Page> getState() => _H5PageState();
}

class _H5PageState extends BasePageState<H5Page> {

  @override
  bool get appBarVisible => true;

  late WebViewController _webViewCtrl;
  late String url;

  @override
  void initState() {
    // setAppBarVisible(false);
    url = Get.arguments['url'] ?? '';
    initWebView();
    super.initState();
  }

  @override
  Widget buildWidget() {
    return WebViewWidget(
      controller: _webViewCtrl
    );
  }

  initWebView() {
    _webViewCtrl = WebViewController.fromPlatformCreationParams(
        const PlatformWebViewControllerCreationParams());

    _webViewCtrl
      ..setJavaScriptMode(JavaScriptMode.unrestricted)
      ..setNavigationDelegate(NavigationDelegate(
          onProgress: (int process) async {
            debugPrint('${await _webViewCtrl.currentUrl()} process: $process');
          },
          onPageFinished: (String value) {

          }
      ))
      ..enableZoom(false)
      // ..addJavaScriptChannel("billeteNative", onMessageReceived: (JavaScriptMessage message) {
      //   Map<String, dynamic> msgJson = jsonDecode(message.message);
      //   debugPrint('msgJson: $msgJson');
      //   var action = msgJson['action'];
      //   if (action == "TouchPoints") {
      //     BuryPoints(_webViewCtrl, msgJson).execute();
      //   }
      // })
      ..loadRequest(Uri.parse(url));
  }

}
